<?php
namespace App\Logic;


use App\Models\SwtDheMachine;
use App\Services\DaHuangService;

class DaHuangeMachineLogic extends BaseLogic {

    /**
     * @notes 获取大黄鹅设备门是否可以开启
     * @param $device_code
     * @return boolean
     * @throws \Illuminate\Http\Client\RequestException
     * @author Evil丿
     * @date 2024/08/30 12:08
     */
    public static function getDoorStatus($device_code)
    {
        $res = DaHuangService::doorCheck($device_code);

        if (!$res['canOpen']) {
            self::$error = $res['errorMsg'];
            return false;
        }

        return true;
    }

    /**
     * @notes 大黄鹅设备开门
     * @param $order_info
     * @return boolean
     * @throws \Illuminate\Http\Client\RequestException
     * @author Evil丿
     * @date 2024/08/30 12:08
     */
    public static function openDoor($order_info)
    {
        $device_code = SwtDheMachine::where('machine_id', $order_info['machine']['id']) ->value('device_code');

        $user_id = $order_info['user_id'];

        $mobile = $order_info['user']['mobile'];

        $res = DaHuangService::openDoor($device_code, $user_id, $mobile);

        return $res;
    }

}
